package pers.qianyu.exception;

/**
 * 业务异常
 *
 * @author mizzle rain
 * @date 2020-10-13 17:51
 */
public class BusinessException extends RuntimeException {
    private final Integer code;

    /**
     * 根据错误枚举初始化业务类异常
     *
     * @param errorCodeEnum 错误枚举
     */
    public BusinessException(ErrorCodeEnum errorCodeEnum) {
        super(errorCodeEnum.getMessage());
        this.code = errorCodeEnum.getCode();
    }

    /**
     * 自定义消息体构造业务类异常
     *
     * @param errorCodeEnum 错误枚举
     * @param message       异常描述
     */
    public BusinessException(ErrorCodeEnum errorCodeEnum, String message) {
        super(message);
        this.code = errorCodeEnum.getCode();
    }

    /**
     * 根据异常构造业务类异常
     *
     * @param errorCodeEnum 错误枚举
     * @param cause         异常
     */
    public BusinessException(ErrorCodeEnum errorCodeEnum, Throwable cause) {
        super(cause.getMessage());
        this.code = errorCodeEnum.getCode();
    }

    public Integer getCode() {
        return code;
    }
}
